﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZhouYu.DreamTour.BLL.IService;
using ZhouYu.DreamTour.DAL.IRepository;
using ZhouYu.DreamTour.Model;
using ZhouYu.DreamTour.ViewModel;

namespace ZhouYu.DreamTour.BLL.Service
{
    public class SpecialtyService: ISpecialtyService
    {
        private ISpecialtyRepository _specialtyRepository;
        public SpecialtyService(ISpecialtyRepository specialtyRepository)
        {
            _specialtyRepository = specialtyRepository;
        }


        #region 地方特产页面信息展示
        /// <summary>
        /// 地方特产页面信息展示
        /// </summary>
        /// <returns></returns>
        public ResponseResult GetGoodsList()
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用地方特产页面展示
            responseResult.data = _specialtyRepository.GetGoodsList();
            return responseResult;
        }
        #endregion


        #region 地方特产页面图片展示
        /// <summary>
        /// 地方特产页面图片展示
        /// </summary>
        /// <returns></returns>
        public ResponseResult GetPictureList()
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用地方特产页面图片展示
            responseResult.data = _specialtyRepository.GetPictureList();
            return responseResult;
        }
        #endregion


        #region 根据Id获取地方特产信息
        /// <summary>
        /// 根据Id获取地方特产信息
        /// </summary>
        /// <returns></returns>
        public ResponseResult GetGoodsInfoById(int GoodsId)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用根据Id获取地方特产信息
            responseResult.data = _specialtyRepository.GetGoodsInfoById(GoodsId);
            return responseResult;
        }
        #endregion


        #region 根据商品Id查询商品发货地
        /// <summary>
        /// 根据商品Id查询商品发货地
        /// </summary>
        /// <param name="TourId"></param>
        /// <returns></returns>
        public ResponseResult CheckStartPlaceByGoodsId(int GoodsId)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用根据商品Id查询商品发货地
            responseResult.data = _specialtyRepository.CheckStartPlaceByGoodsId(GoodsId);
            return responseResult;
        }
        #endregion


        #region 根据用户Id查询商品配送地址
        /// <summary>
        /// 根据用户Id查询商品配送地址
        /// </summary>
        /// <param name="TourId"></param>
        /// <returns></returns>
        public ResponseResult CheckDeliAdressByUser_Id(int User_Id)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用根据用户Id查询商品配送地址
            responseResult.data = _specialtyRepository.CheckDeliAdressByUser_Id(User_Id);
            ////截取配送地址
            //string str = DeliveryAddress.Delivery_Adress.Substring(0,2);
            //DeliveryAddress.Delivery_Adress= str;
            //responseResult.data = DeliveryAddress;
            return responseResult;
        }
        #endregion


        #region 根据订单类型和商品名称查询销售量
        /// <summary>
        /// 根据订单类型和商品名称查询销售量
        /// </summary>
        /// <param name="TourId"></param>
        /// <returns></returns>
        public ResponseResult GetSalesCount(string GoodsName)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用根据订单类型和商品名称查询销售量
            responseResult.data = _specialtyRepository.GetSalesCount(GoodsName);          
            return responseResult;
        }
        #endregion


        #region 根据商品Id获取地方特产详情信息
        /// <summary>
        /// 根据商品Id获取地方特产详情信息
        /// </summary>
        /// <returns></returns>
        public ResponseResult GetGoodsDetailsInfoById(int GoodsId)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用根据商品Id获取地方特产详情信息
            responseResult.data = _specialtyRepository.GetGoodsDetailsInfoById(GoodsId);
            return responseResult;
        }
        #endregion


        #region 查询用户平均点评分数
        /// <summary>
        /// 查询用户平均点评分数
        /// </summary>
        /// <returns></returns>
        public ResponseResult CheckAvgScore(int GoodsId)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用查询用户平均点评分数
            responseResult.data = _specialtyRepository.CheckAvgScore(GoodsId);
            return responseResult;
        }
        #endregion


        #region 查询特产评论数
        /// <summary>
        /// 查询特产评论数
        /// </summary>
        /// <returns></returns>
        public ResponseResult CheckUserCommentCount(int GoodsId)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用查询特产评论数
            responseResult.data = _specialtyRepository.CheckUserCommentCount(GoodsId);
            return responseResult;
        }
        #endregion


        #region 获取商品评论列表
        /// <summary>
        /// 获取商品评论列表
        /// </summary>
        /// <returns></returns>
        public ResponseResult GetUsercommentsList(int GoodsId)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用获取商品评论列表
            responseResult.data = _specialtyRepository.GetUsercommentsList(GoodsId);
            return responseResult;
        }
        #endregion


        #region 根据用户Id查询所有配送地址
        /// <summary>
        /// 根据用户Id查询所有配送地址
        /// </summary>
        /// <param name="TourId"></param>
        /// <returns></returns>
        public ResponseResult CheckAllDeliAdressByUser_Id(int User_Id)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用根据用户Id查询所有配送地址
            responseResult.data = _specialtyRepository.CheckAllDeliAdressByUser_Id(User_Id);
            //deliveryAddressesListOther = _specialtyRepository.CheckAllDeliAdressByUser_Id(User_Id).Skip(2).ToList();
            return responseResult;
        }
        #endregion


        #region 添加商品订单信息
        /// <summary>
        /// 添加商品订单信息
        /// </summary>
        /// <returns></returns>
        public ResponseResult AddGoodsOrderInfo(OrderInfo orderInfo)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //Random random = new Random();          
            //orderInfo.Order_No= random.Next(100000, 999999).ToString();
            //调用添加商品订单信息
            responseResult.Success = _specialtyRepository.AddGoodsOrderInfo(orderInfo) > 0;
            return responseResult;
        }
        #endregion


        #region 根据用户Id查询最新一条订单
        /// <summary>
        /// 根据用户Id查询最新一条订单
        /// </summary>
        /// <returns></returns>
        public ResponseResult CheckNewOrder(int User_Id)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();           
            //调用根据用户Id查询最新一条订单
            responseResult.data = _specialtyRepository.CheckNewOrder(User_Id);
            return responseResult;
        }
        #endregion


        #region 添加订单时同时将收货人信息添加到订单收货中
        /// <summary>
        /// 添加订单时同时将收货人信息添加到订单收货中
        /// </summary>
        /// <returns></returns>
        public ResponseResult AddOrderNowToOrderOver(OrderOver orderOver)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用添加订单时同时将收货人信息添加到订单收货中
            responseResult.Success = _specialtyRepository.AddOrderNowToOrderOver(orderOver)> 0;
            return responseResult;
        }
        #endregion


        #region 根据订单编号查询商品信息
        /// <summary>
        ///根据订单Id查询商品信息
        /// </summary>
        /// <returns></returns>
        public ResponseResult CheckGoodsInfoByOrder_No(string Order_No)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用根据订单编号查询商品信息
            responseResult.data = _specialtyRepository.CheckGoodsInfoByOrder_No(Order_No);
            return responseResult;
        }
        #endregion


        #region 根据订单Id查询收货人信息
        /// <summary>
        ///根据订单Id查询收货人信息
        /// </summary>
        /// <returns></returns>
        public ResponseResult CheckOrderOverInfoByOrder_Id(int Order_Id)
        {            
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用根据订单Id查询收货人信息
            responseResult.data = _specialtyRepository.CheckOrderOverInfoByOrder_Id(Order_Id);
            return responseResult;
        }
        #endregion


        #region 根据订单编号修改订单状态为待评价
        /// <summary>
        ///根据订单编号修改订单状态为待评价
        /// </summary>
        /// <returns></returns>
        public ResponseResult UpdateOrderStatusByOrder_No(string Order_No)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用根据订单编号修改订单状态为待评价
            responseResult.data = _specialtyRepository.UpdateOrderStatusByOrder_No(Order_No);
            return responseResult;
        }
        #endregion
    }
}
